package younian.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;

/**
 * 用户信息类
 * @author Administrator
 *
 */
@Entity
@Table(name = "t_user")
public class User {

	private int id;
	private String nickName; // 昵称
	private String trueName; // 真实姓名
	private String password; // 密码
	private String sex; // 性别
	private String face; // 头像
	private Date regTime; // 注册时间
	private String email; // 邮箱
	private String mobile; // 手机
	private int type; // 用户类型   1：普通用户 ，2：管理员
	private List<Section> sectionList = new ArrayList<Section>();//用户所有主题
	private List<Topic> topicList = new ArrayList<Topic>();//用户所有帖子

	@Id
	@GeneratedValue(generator = "_native")
	@GenericGenerator(name = "_native", strategy = "native")
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(length = 20)
	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	@Column(length = 20)
	public String getTrueName() {
		return trueName;
	}

	public void setTrueName(String trueName) {
		this.trueName = trueName;
	}

	@Column(length = 20)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(length = 20)
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@Column(length = 20)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(length = 10)
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getFace() {
		return face;
	}

	public void setFace(String face) {
		this.face = face;
	}

	public Date getRegTime() {
		return regTime;
	}

	public void setRegTime(Date regTime) {
		this.regTime = regTime;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	@OneToMany(fetch = FetchType.EAGER)
	@JoinColumn(name = "masterId", updatable = false)
	public List<Section> getSectionList() {
		return sectionList;
	}

	public void setSectionList(List<Section> sectionList) {
		this.sectionList = sectionList;
	}

	@OneToMany(mappedBy = "user")
	@Cascade(value = { CascadeType.DELETE })
	public List<Topic> getTopicList() {
		return topicList;
	}

	public void setTopicList(List<Topic> topicList) {
		this.topicList = topicList;
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", nickName=" + nickName + ", trueName=" + trueName + ", password=" + password
				+ ", sex=" + sex + ", face=" + face + ", regTime=" + regTime + ", email=" + email + ", mobile=" + mobile
				+ ", type=" + type + ", sectionList=" + sectionList + ", topicList=" + topicList + "]";
	}
	
}
